package logic

import (
	"context"
	"doc-manager/docrpc/docrpc"
	"doc-manager/docrpc/internal/svc"
	"doc-manager/model/mysql"

	"github.com/zeromicro/go-zero/core/logx"
)

type DocAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewDocAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DocAddLogic {
	return &DocAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *DocAddLogic) DocAdd(in *docrpc.DocAddRequest) (*docrpc.DocAddResponse, error) {
	// todo: add your logic here and delete this line
	doc := mysql.Doc{
		Name:  in.Name,
		Level: in.Level,
		Types: in.Types,
	}
	err := doc.DocAdd(mysql.DB)
	if err != nil {
		return nil, err
	}
	return &docrpc.DocAddResponse{
		DocId: int64(doc.ID),
	}, nil
}
